package com.diaohw.module.system.mapper;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.diaohw.module.system.obj.entity.SysMenuDO;
import com.diaohw.module.system.obj.query.SysMenuQuery;
import com.diaohw.module.system.obj.tables.SysMenuDef;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 部门 映射层。
 *
 * @author D-Hw
 * @since 2024-11-15 18:22:15
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenuDO> {



    static QueryWrapper createWrapper(SysMenuQuery query) {
        QueryWrapper wrapper = QueryWrapper.create();
        wrapper.and(SysMenuDef.SYS_MENU.ICON.like(query.getIcon()).when(StrUtil.isNotBlank(query.getIcon())));
        wrapper.and(SysMenuDef.SYS_MENU.NAME.like(query.getName()).when(StrUtil.isNotBlank(query.getName())));
        wrapper.and(SysMenuDef.SYS_MENU.PERM.like(query.getPerm()).when(StrUtil.isNotBlank(query.getPerm())));
        wrapper.and(SysMenuDef.SYS_MENU.SORT.eq(query.getSort()).when(ObjUtil.isNotNull(query.getSort())));
        wrapper.and(SysMenuDef.SYS_MENU.TYPE.in(query.getType()).when(ObjUtil.isNotEmpty(query.getType())));
        wrapper.and(SysMenuDef.SYS_MENU.MODULE.like(query.getModule()).when(StrUtil.isNotBlank(query.getModule())));
        wrapper.and(SysMenuDef.SYS_MENU.PARAMS.like(query.getParams()).when(StrUtil.isNotBlank(query.getParams())));
        wrapper.and(SysMenuDef.SYS_MENU.VISIBLE.eq(query.getVisible()).when(ObjUtil.isNotNull(query.getVisible())));
        wrapper.and(SysMenuDef.SYS_MENU.PARENT_ID.like(query.getParentId()).when(StrUtil.isNotBlank(query.getParentId())));
        wrapper.and(SysMenuDef.SYS_MENU.REDIRECT.like(query.getRedirect()).when(StrUtil.isNotBlank(query.getRedirect())));
        wrapper.and(SysMenuDef.SYS_MENU.TREE_PATH.like(query.getTreePath()).when(StrUtil.isNotBlank(query.getTreePath())));
        wrapper.and(SysMenuDef.SYS_MENU.COMPONENT.like(query.getComponent()).when(StrUtil.isNotBlank(query.getComponent())));
        wrapper.and(SysMenuDef.SYS_MENU.KEEP_ALIVE.eq(query.getKeepAlive()).when(ObjUtil.isNotNull(query.getKeepAlive())));
        wrapper.and(SysMenuDef.SYS_MENU.ROUTE_NAME.like(query.getRouteName()).when(StrUtil.isNotBlank(query.getRouteName())));
        wrapper.and(SysMenuDef.SYS_MENU.ROUTE_PATH.like(query.getRoutePath()).when(StrUtil.isNotBlank(query.getRoutePath())));
        wrapper.and(SysMenuDef.SYS_MENU.ALWAYS_SHOW.eq(query.getAlwaysShow()).when(ObjUtil.isNotNull(query.getAlwaysShow())));
        return wrapper;
    }
}
